using System;
using Headspring.Training.Core.Model;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;

namespace Headspring.Training.UnitTests.Model
{
	[TestFixture]
	public class EmployeeTester
	{
		[Test]
		public void ConstructorSetsFieldsProperly()
		{
			var employee = new Employee("bobjoe", "Bob", "Joe", "Test");

			Assert.That(employee.EmailAddress, Is.EqualTo("Test"));
			Assert.That(employee.FirstName, Is.EqualTo("Bob"));
			Assert.That(employee.LastName, Is.EqualTo("Joe"));
			Assert.That(employee.UserName, Is.EqualTo("bobjoe"));
		}

		[Test]
		public void FullNameShouldCombineFirstAndLastName()
		{
			var employee = new Employee {FirstName = "Bob", LastName = "Joe"};

			Assert.That(employee.GetFullName(), Is.EqualTo("Bob Joe"));
		}

		[Test]
		public void PropertiesShouldGetAndSetProperly()
		{
			var employee = new Employee();
			Guid guid = Guid.NewGuid();

			employee.EmailAddress = "Test";
			employee.FirstName = "Bob";
			employee.Id = guid;
			employee.LastName = "Joe";
			employee.UserName = "bobjoe";

			Assert.That(employee.EmailAddress, Is.EqualTo("Test"));
			Assert.That(employee.FirstName, Is.EqualTo("Bob"));
			Assert.That(employee.Id, Is.EqualTo(guid));
			Assert.That(employee.LastName, Is.EqualTo("Joe"));
			Assert.That(employee.UserName, Is.EqualTo("bobjoe"));
		}

		[Test]
		public void PropertiesShouldInitializeProperly()
		{
			var employee = new Employee();
			Assert.That(employee.Id, Is.EqualTo(Guid.Empty));
			Assert.That(employee.UserName, Is.EqualTo(null));
			Assert.That(employee.FirstName, Is.EqualTo(null));
			Assert.That(employee.LastName, Is.EqualTo(null));
			Assert.That(employee.EmailAddress, Is.EqualTo(null));
		}

		[Test]
		public void ShouldCompareEmployeesByLastName()
		{
			var employee1 = new Employee("", "1", "1", "");
			var employee2 = new Employee("", "1", "2", "");

			Assert.That(employee1.CompareTo(employee2), Is.EqualTo(-1));
			Assert.That(employee1.CompareTo(employee1), Is.EqualTo(0));
			Assert.That(employee2.CompareTo(employee1), Is.EqualTo(1));
		}


		[Test]
		public void ShouldCompareEmployeesByLastNameThenFirstName()
		{
			var employee1 = new Employee("", "1", "1", "");
			var employee2 = new Employee("", "2", "1", "");

			Assert.That(employee1.CompareTo(employee2), Is.EqualTo(-1));
			Assert.That(employee1.CompareTo(employee1), Is.EqualTo(0));
			Assert.That(employee2.CompareTo(employee1), Is.EqualTo(1));
		}

		[Test]
		public void ShouldNotReportToAnotherManager()
		{
			var employee = new Employee("jsmith", "john", "smith",
			                            "jsmith@company.com");
			var manager1 = new Manager("mhall", "mike", "hall",
			                           "mhall@company.com", null);
			var manager2 = new Manager("bhall", "brad", "hall",
			                           "bhall@company.com", null);

			employee.Id = Guid.NewGuid();
			manager1.Id = Guid.NewGuid();
			manager2.Id = Guid.NewGuid();
			employee.Manager = manager2;

			Assert.That(employee.ReportsTo(manager1), Is.EqualTo(false));
		}

		[Test]
		public void ShouldReportToManager()
		{
			var employee = new Employee("jsmith", "john", "smith",
			                            "jsmith@company.com");
			var manager = new Manager("mhall", "mike", "hall",
			                          "mhall@company.com", null);

			employee.Id = Guid.NewGuid();
			manager.Id = Guid.NewGuid();
			employee.Manager = manager;

			Assert.That(employee.ReportsTo(manager), Is.EqualTo(true));
		}

		[Test]
		public void ShouldReturnEmployeeEmailWhenCallingGetRejectAddress()
		{
			var employee = new Employee("lee", "lee", "brandt", "e@mail.com");

			Assert.AreEqual("e@mail.com", employee.GetRejectEmail(DayOfWeek.Friday));
		}

		[Test]
		public void ToStringShouldReturnFullName()
		{
			var employee = new Employee("", "Joe", "Camel", "");
			Assert.That(employee.ToString(), Is.EqualTo("Joe Camel"));
		}
	}
}